/**
 * 
 */
package com.zznode.client.wlanpolling.other;

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.zznode.client.wlanpolling.R;
import com.zznode.client.wlanpolling.model.WLANPollManager;
import com.zznode.client.wlanpolling.test.PollTestResultActivity;

/**
 * @author Bean
 *
 */
public class TestResultListActivity extends ListActivity {
	private TestResultListAdapter listAdapter;
	private Cursor cursor;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.testresultlist);
		
		cursor = WLANPollManager.getWLANPollManager().loadTestResultCursorFromDb(this);
		listAdapter = new TestResultListAdapter(this, cursor);
		setListAdapter(listAdapter);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		
		if(cursor != null && !cursor.isClosed()) {
			cursor.close();
		}
	}

	@Override
	protected void onListItemClick(ListView listView, View v, int position, long id) {
		if(v.getTag() != null && (v.getTag() instanceof Integer)) {
			Integer _id = (Integer)v.getTag();
			Intent i = new Intent(this, PollTestResultActivity.class);
			i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
			i.putExtra("_id", _id);
			startActivity(i);
		}
	}
}
